#include<iostream>
#include<algorithm>
using namespace std;
const int N=10010;
int fa[N];
struct node
{
	int u;
	int v;
	int c;
}a[N];
int n,m;
	int ret;
	int cnt;
int find(int x)
{
	if(x==fa[x]) return x;
	else return fa[x]=find(fa[x]);
}
bool cmp(node& a,node& b)
{
	return a.c<b.c;
}
void kk()
{

	sort(a+1,a+1+m,cmp);//一定注意这里是m 
	for(int i=1;i<=m;i++)
	{
		int x=a[i].u;int y=a[i].v;int z=a[i].c;
		int fx=find(x);
		int fy=find(y);
		if(fx!=fy)
		{
			ret++;
			cnt=max(cnt,z);
			fa[fx]=fy;
		} 	
		
	}
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>a[i].u>>a[i].v>>a[i].c;
	}
	for(int i=1;i<=n;i++) fa[i]=i;
	kk();
	cout<<ret<<" ";
	cout<<cnt<<endl;
	return 0;
}